angular.module('myApp.controllers', ['ionic'])
//消息Tab页面控制器
.controller('MsgTabController', function($scope,$state) {
    $scope.msgItem_Title=[];
    for (var i=0;i<50;i++){
        $scope.msgItem_Title.push(["消息标题",i+1].join(""));
    };

    $scope.messageDetils = function(message) {
        $state.go("msg_detail", {
            "messageId": message.id
        });
    };


 })
//工作Tab页面控制器
.controller('WorkTabController', function($scope) {

        $scope.title='WorkTabController';

    })
//个人中心Tab页面控制器
.controller('MyTabController', function($scope) {

        $scope.title='MyTabController';

    })

.controller('content1Controller', function($scope,$stateParams) {

        $scope.title='content1Controller';


        console.log($stateParams);

})

//登陆页面控制器
 .controller('LoginController', function($scope,$stateParams,$location,$ionicPopup,$ionicPopover) {
     $scope.loginData = {};
     //--------------------------------------------
     $scope.login = function(user) {

         if(typeof(user)=='undefined'){
             $scope.showAlert('请输入账号密码');
             return false;
         }
         console.log(user.username);

         if(user.username=='123@qq.com' && user.password=='123'){
             $location.path('/tab/msg');
         }else{
             //  alert（警告） 对话框
             $scope.showAlert('请输入账号密码');
         }

     };
     //--------------------------------------------
     $scope.logout = function() {   $location.path('/app/login');   };
     //--------------------------------------------
     // An alert dialog
     $scope.showAlert = function(msg) {
         var alertPopup = $ionicPopup.alert({
             title: 'Warning Message',
             template: msg
         });
     };
     $scope.register = function() {
         $location.path('/register');
     }
 })

 //日报控制器
 .controller('DailyController', function($scope,$stateParams,$ionicPopup) {

        $scope.postDaily=function(info){
            console.log(info.completed);
            console.log(info.uncompleted);
                var confirmPopup = $ionicPopup.confirm({
                    title: '日报',
                    template: '<p><h4>今日完成工作:</h4>'+info.completed+'</p>' +
                    '<p><h4>未完成工作:</h4>'+info.uncompleted+'</p>'+
                    '<p><h4>明日工作计划:</h4>'+info.plan+'</p>'+
                    '<p><h4>需协调工作:</h4>'+info.help+'</p>'+
                    '<p><h4>备注:</h4>'+info.remark+'</p>'
                });
                confirmPopup.then(function(res) {
                    if(res) {
                        //post请求

                    } else {
                    }
                });

        };

    })
 //周报控制器
    .controller('WeeklyController', function($scope,$stateParams,$ionicPopup) {

        $scope.postWeekly=function(info){
            console.log(info.completed);
            console.log(info.uncompleted);
            var confirmPopup = $ionicPopup.confirm({
                title: '日报',
                template: '<p><h4>本周完成工作:</h4>'+info.completed+'</p>' +
                '<p><h4>未完成工作:</h4>'+info.uncompleted+'</p>'+
                '<p><h4>下周工作计划:</h4>'+info.plan+'</p>'+
                '<p><h4>需协调工作:</h4>'+info.help+'</p>'+
                '<p><h4>备注:</h4>'+info.remark+'</p>'
            });
            confirmPopup.then(function(res) {
                if(res) {
                    //post请求

                } else {
                }
            });

        };

    })
    //请假控制器
    .controller('LeaveController', function($scope,$stateParams,$ionicPopup) {
        $scope.leave_type=[];
        for (var i=0;i<4;i++){
            $scope.leave_type.push(["请假类型",i+1].join(""));
        };

        $scope.postLeave=function(info){
            console.log(info.type);
            console.log(info.day);
            console.log(info.reson);
            console.log(info.leader);
            var confirmPopup = $ionicPopup.confirm({
                title: '日报',
                template: '<p><h4>请假类型:</h4>'+info.type+'</p>' +
                '<p><h4>请假时间:</h4>'+info.day+'</p>'+
                '<p><h4>请假理由:</h4>'+info.reson+'</p>'+
                '<p><h4>审批人:</h4>'+info.leader+'</p>'
            });
            confirmPopup.then(function(res) {
                if(res) {
                    //post请求

                } else {
                }
            });

        };

    })

